<?php 
$fullname			= array('id'=>'bill_fullname', 'class'=>'span3 form-control', 'name'=>'fullname', 'value'=> $customer['fullname']);
$email				= array('id'=>'bill_email', 'class'=>'span3 form-control', 'name'=>'email', 'value'=>	$customer['email']);
$phone				= array('id'=>'bill_phone', 'class'=>'span3 form-control', 'name'=>'phone', 'value'=> $customer['phone']);

$check_gender_female = false;
$check_gender_male = false;
if($customer['gender']==0)$check_gender_female = true;
else $check_gender_male = true; 
$gender_female		= array('id'=>'inlineCheckbox3', "checked"=>$check_gender_female, 'class'=>'', 'name'=>'gender', 'value'=>0);
$gender_male		= array('id'=>'inlineCheckbox3',"checked"=>$check_gender_male, 'class'=>'', 'name'=>'gender', 'value'=>1);
$value_birth = "";
if(!empty($customer['birth']))
	$value_birth  = date("d/m/Y",$customer['birth']);
$birth				= array('id'=>'date_birth', 'class'=>'span3 form-control', 'name'=>'birth', 'value'=>$value_birth);
$birth1				= array('id'=>'date_birth1', 'class'=>'span3 form-control', 'name'=>'birth', 'value'=>$value_birth);
$address_billing	= array('id'=>'address_billing', 'class'=>'span3 form-control', 'name'=>'address1', 'value'=>"");
echo theme_css('jquery-ui.css', true);
echo theme_js('jquery-ui.js', true);?>
<style>
.tab_content{display:none;clear:both;border:1px solid #CCC;padding:20px;text-align:justify;border: 1px solid #ccc;background: #f2f2f2;}
#tab ul {margin:0px;padding:0px;}
#tab ul li{list-style:none;float:left;line-height:18px;padding: 5px 10px;border:1px solid #CCC;border-bottom:0px;position:relative;background:#FFF;margin-left:15px;-webkit-border-top-left-radius: 5px;
-moz-border-top-left-radius: 5px;
border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-top-right-radius: 5px;
border-top-right-radius: 5px;
}
#tab ul .active{border-bottom:0px;top:1px;line-height:18px;background: #f2f2f2;}
</style>
<div class="content_wp">
    <div class="container">
        <div class="breadcrumb_wp">
            <ol class="breadcrumb">
              <li><a href="#">Trang Chủ</a></li>
              <li class="active">Đăng ký</li>
            </ol>
        </div>
       <?php $text_success = $this->session->flashdata('success'); if(!empty( $text_success)){?><div class="success"><?php echo  $text_success;?> </div><?php }?>
       <div id="tab">
        	<ul>
                <li><a href="#tabs-1">Thông tin cơ bản</a></li>
                <li><a href="#tabs-2">Đổi mật khẩu</a></li>
                <li><a href="#tabs-3">Danh sách địa chỉ</a></li>
                <li><a href="#tabs-4">Điểm tích lũy</a></li>
                <li><a href="#tabs-5">Thông tin đơn hàng</a></li>
            </ul>
            <?php echo form_open('secure/my_account'); ?>
            <div class="tab_content" id="tabs-1">
               	  <div class="form-group">
                    	<label for="account_fullname"><?php echo lang('account_fullname');?> <span class="red">*</span></label>
						<?php echo form_input($fullname);?>
					</div>
                     <div class="form-group">
						<label for="account_gender"> <?php echo lang("account_birth")?></label>
                        <div class="clear"></div>
                        <?php echo form_input($birth);?>
                     </div>
                     <div class="form-group">
                     	<label for="account_gender"> <?php echo lang("account_gender")?></label>
                        <div class="clear"></div>
                        <label class="checkbox-inline"><?php echo  form_radio($gender_male)?><?php echo lang("acccount_gender_male")?></label>
                        <label class="checkbox-inline"><?php echo  form_radio($gender_female)?><?php echo lang("acccount_gender_female")?></label>
                     </div>
                    <div class="form-group">
						<label for="account_email"><?php echo lang('account_email');?>  (Dùng đăng nhập website) <span class="red">*</span></label>
						<?php echo form_input($email);?>
                    </div>
					<div class="form-group">
						<label for="account_phone"><?php echo lang('account_phone');?> <span class="red">*</span></label>
						<?php echo form_input($phone);?>
                    </div>
                    <input type="submit" value="Cập nhật" class="btn btn-primary" />
            </div>
            <div class="tab_content" id="tabs-2">
            	   <div class="form-group">
						<label for="account_password"><?php echo lang('account_password');?> <span class="red">*</span></label>
						<input cl type="password" name="password" value="" class="span3 form-control" autocomplete="off" />
					</div>
					<div class="form-group">
						<label for="account_confirm"><?php echo lang('account_confirm');?> <span class="red">*</span></label>
						<input type="password" name="confirm" value="" class="span3 form-control" autocomplete="off" />
					</div>
                    <input type="submit" value="Cập nhật" class="btn btn-primary" />
            </div>
            </form>
            <?php echo form_open('secure/address_form/'); ?>
            <div class="tab_content" id="tabs-3">
            <input type="button" class="btn edit_address" style="background:#DADADA;margin-bottom:20px;" rel="0" value="Thêm địa chỉ">
            		<div class="row">
			<div class="span7" id='address_list'>
			<?php if(count($addresses) > 0):?>
				<table class="table table-bordered table-striped">
			<?php
			$c = 1;
				foreach($addresses as $a):?>
					<tr id="address_<?php echo $a['id'];?>">
						<td>
							<?php
							$b	= $a['field_data'];
							$b["area"] = $b["area_code"];
							echo format_address($b, true);
							?>
						</td>
						<td>
							<div class="row-fluid">
								<div class="span12">
									<div class="btn-group pull-right">
										<input type="button" class="btn edit_address" rel="<?php echo $a['id'];?>" value="<?php echo lang('form_edit');?>" />
										<input type="button" class="btn btn-danger delete_address" rel="<?php echo $a['id'];?>" value="<?php echo lang('form_delete');?>" />
									</div>
								</div>
							</div>
							<div class="row-fluid">
								<div class="span12">
									<div class="pull-right" style="padding-top:10px;">
										<input type="radio" name="bill_chk" onclick="set_default(<?php echo $a['id'] ?>, 'bill')" <?php if($customer['default_billing_address']==$a['id']) echo 'checked="checked"'?> /> <?php echo lang('default_billing');?>
										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="ship_chk" onclick="set_default(<?php echo $a['id'] ?>,'ship')" <?php if($customer['default_shipping_address']==$a['id']) echo 'checked="checked"'?>/> <?php echo lang('default_shipping');?>
									</div>
								</div>
							</div>
						</td>
					</tr>
				<?php endforeach;?>
				</table>
			<?php endif;?>
			</div>
			</div>
        </div>
         <div class="tab_content" id="tabs-4">
         		<p><b>Điểm tích lũy gồm có:</b></p>
         		<p> Tổng điểm tích lũy: <strong style="margin-left:5px"> <?php echo $use_score['score'] + $score_cart?></strong> điểm</p>
                <p> Điểm có thể sử dụng mua hàng: <strong style="margin-left:5px"><?php echo $use_score['score']?></strong> điểm</p>
                <p> Điểm đang chờ hoàn tất đơn hàng: <strong style="margin-left:5px"><?php echo $score_cart?></strong> điểm</p>
         </div>
            <div class="tab_content" id="tabs-5">
            
            	<div class="page-header">
                    <h2><?php echo lang('order_history');?></h2>
                </div>
                <?php if($orders):
                    echo $orders_pagination;
                ?>
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th><?php echo lang('order_date');?></th>
                            <th><?php echo lang('order_number');?></th>
                            <th><?php echo lang('order_status');?></th>
                            <th style="width:8%"></th>
                        </tr>
                    </thead>
        
                    <tbody>
                    <?php
                    foreach($orders as $order): ?>
                        <tr>
                            <td>
                                <?php echo format_date_dmY($order->ordered_on); ?>
                            </td>
                            <td><?php echo $order->order_number; ?></td>
                            <td><?php echo $order->status;?></td>
                            <td> <a href="<?php echo site_url("cart/view_detail_order/".$order->order_id)?>" class="order_detail"> Chi tiết </a> </td>
                        </tr>
                
                    <?php endforeach;?>
                    </tbody>
                </table>
                <?php else: ?>
                    <?php echo lang('no_order_history');?>
                <?php endif;?>
            </div>
        </div>
    </div>
</div>
<div id="order_detail" style="display:none">

</div>
<div id="address-form-container" style="display:none">

</div>
<script>
var hash = window.location.hash.substring(1);
var ajax = null;
var site_url = "<?php echo site_url()?>";
active_tab(hash);
function active_tab(hash){
	if(hash == null || hash == ""){
		$(".tab_content").eq(0).css("display","block");
		$("#tab ul li").eq(0).addClass("active");
	}else{
		$index_active = $("#"+hash).index() - 1;
		$(".tab_content").eq($index_active).css("display","block");
		$("#tab ul li").eq($index_active).addClass("active");
	}	
}
$("#tab ul li a").on("click",function(){
  $(".tab_content").css("display","none");
  var $index = $("#tab ul li a").index(this);
  $("#tab ul li").removeClass("active");
  $($(this).attr("href")).css("display","block");
  $("#tab ul li").eq($index).addClass("active");
  return false;
  
});
$("#date_birth").datepicker({
	dateFormat:"dd/mm/yy",	
	changeYear: true,
	changeMonth:true,
	monthNamesShort:[1,2,3,4,5,6,7,8,9,10,11,12],
	yearRange:"1975:-10",
});
$("#date_birth1").datepicker({
	dateFormat:"dd/mm/yy",	
	changeYear: true,
	changeMonth:true,
	monthNamesShort:[1,2,3,4,5,6,7,8,9,10,11,12],
	yearRange:"1975:-10",
});
$("select[name='location_zone']").change(function(){
	if(ajax != null)
		ajax.abort();
	ajax = $.ajax({
		url:site_url+"secure/zone_area",
		data:"zoneid="+$(this).val(),
		type:"POST",
		success:function(result){
			$("select[name='zone_area']").html(result);
		}
	});
});
$('.delete_address').click(function(){
	if($('.delete_address').length > 1){
		if(confirm('Are you sure you want to delete this address?')){
			$.post("<?php echo site_url("secure/delete_address")?>", { id: $(this).attr('rel') },
			function(data){
				$('#address_'+data).remove();
				$('#address_list .my_account_address').removeClass('address_bg');
				$('#address_list .my_account_address:even').addClass('address_bg');
			});
		}
	}
	else{
		alert('You Must leave at least 1 address in the Address Manager.');
	}	
});
$('.edit_address').click(function(){
	$.post('<?php echo site_url("secure/address_form/")?>/'+$(this).attr('rel'),
		function(data){
			$('#address-form-container').html(data).modal().modal('show');
		}
	);
});
$(".order_detail").click(function(){
	$.get($(this).attr("href"),function(data){
		$('#order_detail').html(data).modal().modal('show');
	});
	return false;	
})
</script>